package org.vnl.platform.orm;

import java.util.Collection;

/**
 * 掌控真正的存取問題,從DB到OBJECT及從OBJECT到DB
 * 
 * @author Vaughan
 *
 */
public interface IPersistenceManager {

    /**
     * Start transaction
     */
    public void begin();
    
    /**
     * Commit current transaction
     */
    public void commit();
    
    /**
     * Rollback current transaction
     */
    public void rollback();
    
    /**
     * Execute database save(insert, update or delete) action
     * @param obj
     */
    public void save(Command obj);
    
    /**
     * Create an Entity
     * @param obj
     */
    public void create(Command obj);
    
    /**
     * Update an Entity
     * @param obj
     */
    public void update(Command obj);
    
    /**
     * Delete an Entity
     * @param obj
     */
    public void delete(Command obj);
    
    /**
     * 
     * @param obj
     * @return
     */
    public Collection<? extends Object> query(QueryCommand obj);
    
    /**
     * 
     * @param key
     * @return
     */
    public Object getByKey(QueryCommand key);
    
    /**
     * 
     * @param currentPage
     * @param pageSize
     * @param obj
     * @return
     */
    public PageResult queryPage(int currentPage, int pageSize, QueryCommand obj);
    
    /**
     * 
     * @param cm
     */
    public void setConnectionManager(IConnectionManager cm);
    
    
    /**
     * 是否需要rollback
     * @return
     */
    public boolean isRollbackOnly();
    
    /**
     * 設定是否需要rollback
     * @param rollbackOnly
     */
    public void setRollbackOnly(boolean rollbackOnly);
}
